package cn.it.service.impl;

import cn.it.dao.PermissionDao;
import cn.it.entity.PageResult;
import cn.it.entity.QueryPageBean;
import cn.it.pojo.Permission;
import cn.it.service.PermissionService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {


    @Autowired
    private PermissionDao permissionDao;

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();

        PageHelper.startPage(currentPage, pageSize);
        Page<Permission> page = permissionDao.selectByCondition(queryString);

        long total = page.getTotal();
        List<Permission> list = page.getResult();

        return new PageResult(total, list);
    }

    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    @Override
    public void deleteId(Integer id) {
        permissionDao.deleteId(id);
    }

    @Override
    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }
}
